﻿namespace ReagentStore.PRT
{
	public class EntityEventArgs
	{
		public EntityEventArgs(object argument)
		{
			Argument = argument;
		}

		public object Argument { get; private set; }
	}

	public delegate void EntityEventHandler(object sender, EntityEventArgs e);

	public class EntityEventProxy
	{
		protected event EntityEventHandler EntityUpdatedEvent;

		public virtual void RaiseEvent(object sender, EntityEventArgs eventArgs)
		{
			if (sender == null)
				return;

			EntityEventHandler handler = EntityUpdatedEvent;
			if (handler != null)
				handler(sender, eventArgs);
		}

		public void Attach(EntityEventHandler handler)
		{
			EntityUpdatedEvent += handler;
		}

		public void Detach(EntityEventHandler handler)
		{
			if (EntityUpdatedEvent != null)
				EntityUpdatedEvent -= handler;
		}
	}
}